/// 工具模型 - Tool Model
/// 
/// 根据后端JSON数据结构定义，用于数据转换
/// Defined based on backend JSON data structure for data conversion
class Tool {
  final String? id;
  final String? name;
  final String? description;
  final String? iconUrl;
  final String? categoryId;
  final String? toolType; // 工具类型：calculator, converter, generator等
  final bool? isFree;
  final bool? isAvailable;
  final bool? isFavorite;
  final int? usageCount;
  final Map<String, dynamic>? config; // 工具配置参数

  const Tool({
    this.id,
    this.name,
    this.description,
    this.iconUrl,
    this.categoryId,
    this.toolType,
    this.isFree,
    this.isAvailable,
    this.isFavorite,
    this.usageCount,
    this.config,
  });

  /// 从JSON创建模型 - Create model from JSON
  factory Tool.fromJson(Map<String, dynamic> json) {
    return Tool(
      id: json['id']?.toString(),
      name: json['name']?.toString(),
      description: json['description']?.toString(),
      iconUrl: json['iconUrl']?.toString(),
      categoryId: json['categoryId']?.toString(),
      toolType: json['toolType']?.toString(),
      isFree: json['isFree'],
      isAvailable: json['isAvailable'],
      isFavorite: json['isFavorite'],
      usageCount: json['usageCount']?.toInt(),
      config: json['config'] as Map<String, dynamic>?,
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'description': description,
      'iconUrl': iconUrl,
      'categoryId': categoryId,
      'toolType': toolType,
      'isFree': isFree,
      'isAvailable': isAvailable,
      'isFavorite': isFavorite,
      'usageCount': usageCount,
      'config': config,
    };
  }
}